Completed
Push — master ( 1fc2c9...675e71 )
by greg
01:46
created

remove.js ➔ remove   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 12
rs 9.4285
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A remove.js ➔ ... ➔ ??? 0 3 1
1
import path from 'path'
2
import fse from 'fs-extra'
3
4
import {
5
  Hooks,
6
  cmsData,
7
  coreUtils,
8
  cmsOperations,
9
  Manager
10
} from '../../'
11
12
13
export function remove(filePath) {
14
  filePath = coreUtils.slug.clean(filePath)
15
  filePath = Hooks.instance.trigger('beforeDeleteFile', filePath)
16
17
  var revisions = cmsData.revision.getVersions(filePath)
18
19
  Array.prototype.forEach.call(revisions, (revision) => {
20
    cmsOperations.remove.removeFile(revision.path, revision.htmlPath)
21
  })
22
23
  Manager.instance.updateList()
24
}
25
26
export function removeFile(file, json) {
27
  if(coreUtils.file.exist(file)) {
28
    fse.removeSync(file)
29
  }
30
31
  if(coreUtils.file.exist(json)) {
32
    fse.removeSync(json)
33
  }
34
}
35
36
export function olderRevisionByType(fileName, type) {
37
  var folder = fileName.split('/')
38
  var file = folder.pop()
39
  var extension = file.replace(/.*?\./, '')
40
  folder = folder.join('/')
41
  var stat = fse.statSync(folder)
42
  if(stat){
43
    var files = FileParser.getFiles(folder, true, 1, new RegExp('\\.' + extension))
0 ignored issues
show
Bug introduced by
The variable FileParser seems to be never declared. If this is a global, consider adding a /** global: FileParser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
    files.forEach(function (fileItem) {
45
      var fname = cmsData.fileAttr.delete(fileItem.cleanPath)
46
      var ftype = cmsData.fileAttr.get(fileItem.cleanPath).s
47
      if(fname === file && ftype === type){
48
        var fileDraft = fileItem.path.replace(/-abe-./, '-abe-d')
49
        cmsOperations.remove.removeFile(fileItem.path, FileParser.changePathEnv(fileItem.path, config.data.url).replace(new RegExp('\\.' + extension), '.json'))
0 ignored issues
show
Bug introduced by
The variable config seems to be never declared. If this is a global, consider adding a /** global: config */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileParser seems to be never declared. If this is a global, consider adding a /** global: FileParser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
50
        cmsOperations.remove.removeFile(fileDraft, FileParser.changePathEnv(fileDraft, config.data.url).replace(new RegExp('\\.' + extension), '.json'))
51
      }
52
    })
53
  }
54
}